package com.panshi.controller;

import com.alibaba.fastjson.JSONArray;
import com.panshi.api.CarouselApi;
import com.panshi.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Autowired
    private CarouselApi carouselApi;

    @GetMapping("/listTable")
    public Map<String,Object> listCarousel(){

        R r = carouselApi.listCarousel(new StatusVO());
        return r.getData();
    }

    @PutMapping
    public R editCarousel(@RequestBody CarouselVO carouselVO){
        return carouselApi.editCarousel(carouselVO);
    }

    @PostMapping
    public R addCarousel(@RequestBody CarouselVO carouselVO){
        return carouselApi.addCarousel(carouselVO);
    }


    /*@PostMapping("/list")
    public ModelAndView getCarouselJson(ModelAndView modelAndView){
        StatusVO statusVO = new StatusVO();
        statusVO.setStatus(Constant.REPLY_STATUS_1);
        R r = carouselApi.listCarousel(statusVO);
        modelAndView.addObject("collect",r.getData().get("data"));
        modelAndView.setViewName("page/banner/carousel");
        return modelAndView;
    }*/

    @PostMapping("/list")
    public R getCarouselJson(){
        StatusVO statusVO = new StatusVO();
        statusVO.setStatus(Constant.REPLY_STATUS_1);
        return carouselApi.listCarousel(statusVO);
    }
    
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        return null;
    }
}
